// pages/order/refund_list/refund_list.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    pageloadding:false,
    p:1
  },
  getOrderlist:function(p){
    let data={token:app.globalData.token,p,typeid: 4}
    console.log("tangyin")
    console.log(data)
    /**
     * 售后订单接口地址Order/refund_list
     */
    app.requestJs('Order/orderlist',{data}).then((res)=>{
      // console.log(res)
      // return false
      if(res.errcode==1){
        let resData=res.data || [];
        resData.forEach(item => {
          console.log(item);
          item.orderstatus_1=item.orderstatus.includes(1);
          item.orderstatus_2=item.orderstatus.includes(2);
          item.orderstatus_3=item.orderstatus.includes(3);
          item.orderstatus_4=item.orderstatus.includes(4);
          item.orderstatus_5=item.orderstatus.includes(5);
          item.orderstatus_6=item.orderstatus.includes(6);
          item.orderstatus_7=item.orderstatus.includes(7);
          item.orderstatus_8=item.orderstatus.includes(8);
          item.orderstatus_9=item.orderstatus.includes(9);
          item.orderstatus_10=item.orderstatus.includes(10);
        });
        this.setData({
          list:data.p==1?resData:[...this.data.list,...resData],
          pageloadding:resData.length>=10?false:true,
          p:data.p
        })
      }else app.utilJs.toast({ title: res.message });
    })
  },
  orderbind_before:function(e){
    let index=e.currentTarget.dataset.index,
        obj=this.data.list[index],
        orderid=obj.orderid,
        orderstatus=e.currentTarget.dataset.typeid;
        console.log(e);
        console.log(obj);
    if(orderstatus==7)wx.navigateTo({url: '/pages/order/express_info/express_info?orderid='+orderid})
    else {
      let data={orderid,orderstatus,token:app.globalData.token};
      this.orderStateBtn(data);
    }
  },
  orderStateBtn:function(data){//订单聚合操作
    app.requestJs("order/orderjuhehander",{data}).then((res) => {
      if (res.errcode == 1) {
        app.utilJs.toast({ title: res.message,icon:'success'});
        this.getOrderlist(1);
      } else {
        app.utilJs.toast({ title: res.message });
      }
    })
  },
  orderInfoLink:function(e){
    let that=this;
    let ordersn=e.currentTarget.dataset.ordersn;
    wx.navigateTo({
      url: '/pages/order/orderinfo/orderinfo?ordersn='+ordersn,
      events:{
        updateData:function(){
          that.getOrderlist(1);
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOrderlist(1);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.pageloadding)return;
    let p=this.data.p+1;
    this.getOrderlist(p);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})